package cn.edu.live.util;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.Properties;

public class PropertyKit {

	/**
	 * 加载 res下的properties文件到内存中
	 * 
	 * @param filePath
	 * @return
	 */
	public static Properties load(String fileName) {
		// InputStream inputStream =
		// PropertyKit.class.getClassLoader().getResourceAsStream(filePath);
		Properties p = new Properties();
		Reader reader = null;
		try {
			String path = PropertyKit.class.getResource("/").getPath() + fileName;
			System.out.println("load config file from " + path);
			reader = new FileReader(new File(path));
			p.load(reader);
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return p;
	}

	public static void main(String[] args) {
		Properties p = PropertyKit.load("res/baseconfig.properties");
		System.out.println(p.getProperty("baseUploadPath"));
	}
}
